package app.consumer;

import biz.paluch.spinach.DisqueClient;
import biz.paluch.spinach.DisqueURI;
import biz.paluch.spinach.api.Job;
import biz.paluch.spinach.api.sync.DisqueCommands;
import com.github.xetorthio.jedisque.Jedisque;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import redis.clients.jedis.exceptions.JedisConnectionException;

import java.util.List;

/**
 * @author faith.huan 2018-09-02 16:30
 */
@Slf4j
@Service
@Profile("spinach")
public class SpDisqueConsumer {


    @Scheduled(fixedDelay = 100)

    public void consume() {

        int i = 0;
        DisqueClient client = DisqueClient.create(DisqueURI.create("47.105.39.155", 50711));
        DisqueCommands commands = client.connect().sync();
        while (true) {
            i++;
            try {
                System.out.println("-----------------" + i);
                log.info("getJob");
                Job job = commands.getjob("que01");
                String jobId = job.getId();
                log.info("第{}次处理,jobID:{},body:{}", i, jobId, job.getBody());
                long ackNum = commands.ackjob(jobId);
                log.info("ackNum:{}", ackNum);
                Thread.sleep(100);
            } catch (Exception e) {
                log.error("xxxxxxxxxxxxxx", e);
            }
        }
    }
}
